package com.das.mechanic_base.widget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.adapter.maintain.X3MaintainPlanAdapter;
import com.das.mechanic_base.base.X3BaseBottomSheetDialog;
import com.das.mechanic_base.base.X3IBaseView;
import com.das.mechanic_base.bean.maintain.MainTainPlanBean;
import com.das.mechanic_base.mapi.api.NetWorkHttp;
import com.das.mechanic_base.mapi.response.HttpCallBack;
import com.das.mechanic_base.mapi.schedulers.RxSchedulersHelper;
import com.das.mechanic_base.utils.X3StringUtils;
import com.kproduce.roundcorners.RoundTextView;
import com.umeng.analytics.MobclickAgent;

import java.util.List;

/**
 * 保养计划
 */
public class X3MaintainPlaneOptionDialog extends Dialog implements View.OnClickListener {
    private Point mScreenPoint = new Point();
    private Context mContext ;

    /**
     * 没有按钮的提示dialog
     */
    public X3MaintainPlaneOptionDialog(Context arg,OnItemClick onItemClick) {
        super(arg, R.style.pointDialog);
        mContext = arg;
        this.onItemClick = onItemClick;
    }

    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setBackgroundDrawable(new BitmapDrawable());
        this.setContentView(R.layout.x3_maintain_plan_option_dialog);
        initDialogWindow();
        initView();
    }

    void initView() {
       LinearLayout ll_implement = findViewById(R.id.ll_implement);
       LinearLayout ll_edite = findViewById(R.id.ll_edite);
       LinearLayout ll_delete = findViewById(R.id.ll_delete);
       ll_implement.setOnClickListener(this);
       ll_edite.setOnClickListener(this);
       ll_delete.setOnClickListener(this);
    }

    OnItemClick onItemClick;

    @Override
    public void onClick(View v) {
      if (v.getId() == R.id.ll_implement){
          onItemClick.onItemClick(0);
      }else if (v.getId() == R.id.ll_edite){
          onItemClick.onItemClick(1);
      }else if (v.getId() == R.id.ll_delete){
          onItemClick.onItemClick(2);
      }
      dismiss();
    }

    public interface OnItemClick {
        void onItemClick(int index);
    }

    @SuppressWarnings("deprecation")
    private void initDialogWindow() {
        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
        WindowManager m = dialogWindow.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        try {
            d.getSize(mScreenPoint);
        } catch (NoSuchMethodError ignore) {
            mScreenPoint.x = d.getWidth();
            mScreenPoint.y = d.getHeight();
        }
        dialogWindow.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        WindowManager.LayoutParams p = dialogWindow.getAttributes();
        p.width = (int) (mScreenPoint.x * 0.74);
        dialogWindow.setAttributes(p);
    }

}
